package org.jaaksi.commondemo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;

/**
 * 创建时间：2017年04月05日20:14 <br>
 * 作者：fuchaoyang <br>
 * 描述：
 */

public class MyButton extends Button {
  public MyButton(Context context) {
    super(context);
  }

  public MyButton(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override protected void onDraw(Canvas canvas) {
    System.out.println("=========MyButton onDraw ============");
    super.onDraw(canvas);
  }

  @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    System.out.println("=========MyButton onLayout ============");
    super.onLayout(changed, left, top, right, bottom);
  }

  @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    System.out.println("=========MyButton onMeasure ============");
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }

  @Override public boolean onTouchEvent(MotionEvent event) {
    System.out.println("=========MyButton onTouchEvent ============");
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      // 如果子view消费down事件但是，不消费move事件会有什么情况呢
      // 1.还能接收up事件吗？答案会的。只要消费了down事件，move和up事件都会过来
      // 2.move不消费，那么ViewGroup会onTouchEvent会接收到move事件吗？ 不会，而是跳过该ViewGroup向上传递
      return true;
    }
    //return super.onTouchEvent(event);
    return false;
  }
}
